---
title: keyof
description: Creates a picklist schema of object keys.
source: /methods/keyof/keyof.ts
contributors:
  - fabian-hiller
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# keyof

Creates a picklist schema of object keys.

```ts
const Schema = v.keyof<TSchema, TMessage>(schema, message);
```

## Generics

- `TSchema` <Property {...properties.TSchema} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `schema` <Property {...properties.schema} />
- `message` <Property {...properties.message} />

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `keyof` can be used.

### Object key schema

Schema to validate the keys of an object.

```ts
const ObjectSchema = v.object({ key1: v.string(), key2: v.number() });
const ObjectKeySchema = v.keyof(ObjectSchema); // 'key1' | 'key2'
```

## Related

The following APIs can be combined with `keyof`.

### Schemas

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
    'unwrap',
  ]}
/>

### Actions

<ApiList
  items={[
    'check',
    'brand',
    'description',
    'flavor',
    'metadata',
    'rawCheck',
    'rawTransform',
    'readonly',
    'title',
    'transform',
  ]}
/>

### Utils

<ApiList items={['isOfKind', 'isOfType']} />

### Async

<ApiList
  items={[
    'arrayAsync',
    'customAsync',
    'exactOptionalAsync',
    'fallbackAsync',
    'intersectAsync',
    'lazyAsync',
    'looseObjectAsync',
    'looseTupleAsync',
    'mapAsync',
    'nonNullableAsync',
    'nonNullishAsync',
    'nonOptionalAsync',
    'nullableAsync',
    'nullishAsync',
    'objectAsync',
    'objectWithRestAsync',
    'optionalAsync',
    'partialAsync',
    'pipeAsync',
    'recordAsync',
    'requiredAsync',
    'setAsync',
    'strictObjectAsync',
    'strictTupleAsync',
    'tupleAsync',
    'tupleWithRestAsync',
    'unionAsync',
    'variantAsync',
  ]}
/>
